import { debounce } from "common/utils";
import { POP, NEW, SELL } from "common/const";
import { BACKTOP_DISTANCE } from "common/const";
import BackTop from "components/content/backtop/BackTop";

export const itemListenerMixin = {
  data() {
    return {
      itemImgListenter: null,
      newrefresh: null
    };
  },
  mounted() {
    //监听图片加载完成
    this.newrefresh = debounce(this.$refs.scroll.refresh, 100);
    this.itemImgListenter = () => {
      this.newrefresh();
    };
    this.$bus.$on("homeitemImageLoad", this.itemImgListenter);
  }
};

//回到顶部的混入
export const backTopMixin = {
  components: {
    BackTop
  },
  data() {
    return {
      isShowBackTop: false
    };
  },
  methods: {
    backClick() {
      this.$refs.scroll.scrollTo(0, 0, 300);
    },
    listenScroll(position) {
      this.isShowBackTop = -position.y > BACKTOP_DISTANCE;
    }
  }
};

//tab栏点击切换
export const tabControlMinXin = {
  data() {
    return {
      currentType: POP
    };
  },
  methods: {
    //3-2推荐数据获取点击切换
    tabClick(index) {
      switch (index) {
        case 0:
          this.currentType = POP;
          break;
        case 1:
          this.currentType = NEW;
          break;
        case 2:
          this.currentType = SELL;
          break;
      }
    }
  }
};
